﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using Enterprise.Model.User;
using Enterprise.Service.User;
using Enterprise.Model.Department;
using Enterprise.Service.Department;
namespace Enterprise.UI.Web
{
    public partial class Contract : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected string CreateContract()
        {
            StringBuilder sb = new StringBuilder();
            DepartmentService dService = new DepartmentService();
            List<DepartmentEntity> dlist = dService.DepartmentList().OrderBy(p=>p.DORDERBY).ToList();
            sb.Append("<table class=\"GridViewStyle\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">");
            sb.Append("<tr class=\"GridViewHeaderStyle\"><th width=\"140\" align=\"center\" height=\"28\">部门</th><th width=\"80\" align=\"center\">人员</th><th align=\"center\">出生日期</th><th align=\"center\">海外手机</th><th align=\"center\">国内手机</th><th align=\"center\">SIPC邮箱</th><th align=\"center\">其他邮箱</th></tr>");
            UserService uService = new UserService();
            foreach (DepartmentEntity dEntity in dlist)
            {
                int i = 0;
                List<UserEntity> ulist = uService.UserList().Where(p => p.DEPTID == dEntity.DEPTID).OrderBy(p=>p.UORDERBY).ToList();
                foreach (UserEntity uEntity in ulist)
                {
                    if (i == 0)
                    {
                        sb.Append("<tr><td rowspan=" + ulist.Count + " align=\"center\" valign=\"center\">" + dEntity.DNAME + "</td><td height=\"25\"  align=\"center\">" + uEntity.UNAME + "</td><td align=\"center\">" + uEntity.UBIRTHDAY.ToShortDateString() + "</td><td align=\"center\">" + uEntity.UHWPHONE + "</td><td align=\"center\">" + uEntity.UGNPHONE + "</td><td align=\"center\">" + uEntity.SIPCEMAIL + "</td><td align=\"center\">" + uEntity.OTHEREMAIL + "</td></tr>");
                    }
                    else
                    {
                        sb.Append("<tr><td height=\"25\"  align=\"center\">" + uEntity.UNAME + "</td><td align=\"center\">" + uEntity.UBIRTHDAY.ToShortDateString() + "</td><td align=\"center\">" + uEntity.UHWPHONE + "</td><td align=\"center\">" + uEntity.UGNPHONE + "</td><td align=\"center\">" + uEntity.SIPCEMAIL + "</td><td align=\"center\">" + uEntity.OTHEREMAIL + "</td></tr>");
                    }
                    i++;
                }
            }
            sb.Append("</table>");
            return sb.ToString();
        }

    }
}